package com.wed.db;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Scanner;

import javax.jws.soap.SOAPBinding.Use;

import com.sun.org.apache.xalan.internal.xsltc.dom.LoadDocument;

/**
 * This class used : open/close Connect to DB and create Query
 * 
 * @author kobe
 */
public class ConnectDB {

	Connection connect = null;
	Statement stmt = null;
	ResultSet rs = null;

	/**
	 * Check Driver connect to MySQL
	 */
	protected void hasDriver() throws Exception {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException ex) {
			throw new Exception("Invalid Driver!!Please check this drver....");
		}
	}

	/**
	 * Function used to get the connection to the Database Step 1 - I check my
	 * connection or not!! Step 2 - If not, it will be null and initialization.
	 * Step 3 - Then it return
	 * 
	 * @return Connection
	 */
	protected Connection openConnect() throws Exception {
		if (connect == null) {
			hasDriver();
			String url = "jdbc:mysql://localhost/conceptmap";
			// url_sql = "....";
			try {
				this.connect = DriverManager.getConnection(url, "root",
						"23041993");
			} catch (SQLException e) {
				throw new Exception(e.getMessage()
						+ "Connect failed to database .... ");
			}
		}
		return connect;
	}

	/**
	 * Make a Statement to execute the SQL statement
	 * 
	 * @return Statement
	 */
	protected Statement getStatement() throws SQLException, Exception {
		if (stmt == null) {
			stmt = openConnect().createStatement();
		}
		return stmt;
	}

	/**
	 * Used to execute the Select statement
	 * 
	 * @param strSQL
	 *            Query VD: Select * from Employee
	 * @return ResultSet
	 */
	/**	
	 * ds acount
	 */
	public ArrayList<User> getListUser() {
		String sql = "select UserName,Password,RoleID from user";
		ArrayList<User> lst = new ArrayList<User>();
		try {
			rs = getStatement().executeQuery(sql);
			while (rs.next()) {
				String user = rs.getString("UserName");
				String pass = rs.getString("PassWord");
				int role =Integer.parseInt(rs.getString("RoleID"));

				User sp = new User(user, pass,role);
				lst.add(sp);
			}
		} catch (Exception e) {
		}
		return lst;

	}
	/**
	 * ds lop
	 */
	public ArrayList<User> getListClass() {
		String sql = "select DISTINCT classID from  conceptmap.user where RoleID=0";
		ArrayList<User> lst = new ArrayList<User>();
		try {
			rs = getStatement().executeQuery(sql);
			while (rs.next()) {
				
				String classid = rs.getString("classID");
			

				User sp = new User(classid);
				lst.add(sp);
			}
		} catch (Exception e) {
		}
		return lst;

	}
	/**
	 * danh sach lop duoc giao bt
	 */
	public ArrayList<User_Assi> getListClassGive(int ass) {
		String sql = "select * from  user_assi where assi="+ass+"";
		ArrayList<User_Assi> lst = new ArrayList<User_Assi>();
		try {
			rs = getStatement().executeQuery(sql);
			while (rs.next()) {
				
				int assi = Integer.parseInt(rs.getString("assi"));
				String classid = rs.getString("classID");
				String date = rs.getString("date");
				String user = rs.getString("username");
			

				User_Assi us = new User_Assi(classid,assi,date,user);
				lst.add(us);
			}
		} catch (Exception e) {
		}
		return lst;

	}
	/**
	 * ds  sinh vien theo ma lop
	 */
	public ArrayList<User> getListStudentByClassID(String classid) {
		String sql = "select * from  user where classID='"+classid+"'";
		ArrayList<User> lst = new ArrayList<User>();
		try {
			rs = getStatement().executeQuery(sql);
			while (rs.next()) {
				
				String username = rs.getString("UserName");
				String classi = rs.getString("classID");
			

				User sp = new User(username,classi);
				lst.add(sp);
			}
		} catch (Exception e) {
		}
		return lst;

	}
	/**
	 * ds user assi theo lop
	 */
	public ArrayList<User_Assi> getuserAss(String Class) {
		String sql = "select * from user_assi where classid='"+Class+"'";
		ArrayList<User_Assi> lst = new ArrayList<User_Assi>();
		try {
			rs = getStatement().executeQuery(sql);
			while (rs.next()) {
				int id = Integer.parseInt(rs.getString("id"));
				int assid = Integer.parseInt(rs.getString("assi"));
				String classid = rs.getString("classid");
				String date=rs.getString("date");

				User_Assi ua = new User_Assi(id,classid,assid,date);
				lst.add(ua);
			}
		} catch (Exception e) {
		}
		return lst;

	}
	/**
	 * ds assignment leature theo ma giang vien
	 */
	public ArrayList<assignment> getAssignment(String user) {
		String sql = "select * from assignment where lecture='"+user+"'";
		ArrayList<assignment> lst = new ArrayList<assignment>();
		try {
			rs = getStatement().executeQuery(sql);
			while (rs.next()) {
				int assid = Integer.parseInt(rs.getString("assgnmentId"));
				String assname = rs.getString("assignmentname");
				String  description =rs.getString("description");
				String datecreate=rs.getString("dateCreate");
				String deadLine=rs.getString("deadLine");
				String lecture=rs.getString("lecture");

				assignment sp = new assignment(assid, assname,description,datecreate,deadLine,lecture);
				lst.add(sp);
			}
		} catch (Exception e) {
		}
		return lst;

	}
	/**
	 * ds cmaplecture leature chua lam
	 */
	public ArrayList<assignment> getAssLec(String user) {
		String sql = "select * from assignment where lecture='"+user+"' and state='"+0+"'";
		ArrayList<assignment> lst = new ArrayList<assignment>();
		try {
			rs = getStatement().executeQuery(sql);
			while (rs.next()) {
				int assi = Integer.parseInt(rs.getString("assgnmentId"));
				String assignmentname = rs.getString("assignmentname");
				String dateCreate = rs.getString("dateCreate");
				String deadLine = rs.getString("deadLine");
				String description = rs.getString("description");
				

				assignment sp = new assignment(assi, assignmentname,description,dateCreate,deadLine);
				lst.add(sp);
			}
		} catch (Exception e) {
		}
		return lst;

	}
	/**
	 * ds assiment duoc giao
	 */
	public ArrayList<User_Assi> getAssStudent(String user) {
		String sql = "select * from user_assi where username='"+user+"' ";
		ArrayList<User_Assi> lst = new ArrayList<User_Assi>();
		try {
			rs = getStatement().executeQuery(sql);
			while (rs.next()) {
				int assi = Integer.parseInt(rs.getString("assi"));
				String classid = rs.getString("classid");
				String date = rs.getString("date");
			
				

				User_Assi sp = new User_Assi(classid,assi, date);
				lst.add(sp);
			}
		} catch (Exception e) {
		}
		return lst;

	}
	/**
	 * ds receive sinh vien theo usereceive
	 */
	public ArrayList<ListShareStudent> getListVersionByid(String user) {
		String sql = "select * from listsharestudent where UserReceive='"+user+"'";
		ArrayList<ListShareStudent> lst = new ArrayList<ListShareStudent>();
		try {
			rs = getStatement().executeQuery(sql);
			while (rs.next()) {
				int cmapver = Integer.parseInt(rs.getString("CmapVersion"));
				String userShare = rs.getString("UserShare");
				String userReceive = rs.getString("UserReceive");
				String dateShare = rs.getString("DateShare");
				ListShareStudent sp = new ListShareStudent(userShare, userReceive,cmapver,dateShare);
				lst.add(sp);
			}
		} catch (Exception e) {
		}
		return lst;

	}
	/**
	 * ds cmaplecture leature da lam
	 */
	
	public ArrayList<assignment> getAssLecDaLam(String user) {
		String sql = "select * from assignment where lecture='"+user+"' and state='"+1+"'";
		ArrayList<assignment> lst = new ArrayList<assignment>();
		try {
			rs = getStatement().executeQuery(sql);
			while (rs.next()) {
				int assi = Integer.parseInt(rs.getString("assgnmentId"));
				String assignmentname = rs.getString("assignmentname");
				String dateCreate = rs.getString("dateCreate");
				String deadLine = rs.getString("deadLine");
				String description = rs.getString("description");
				

				assignment sp = new assignment(assi, assignmentname,description,dateCreate,deadLine);
				lst.add(sp);
			}
		} catch (Exception e) {
		}
		return lst;

	}
	/**
	 * update tinh trang cmap
	 */
	public boolean UpDateAssignment(int ass) throws Exception {
		String sql = "update assignment set state=1 where assgnmentId="+ass+"";
		PreparedStatement pst = openConnect().prepareStatement(sql);
		
		
		return pst.executeUpdate() > 0;
	}
	/**
	 * update tinh trang cmapstudent
	 */
	public boolean UpDateCmapstudent(int version) throws Exception {
		String sql = "update cmapstudent set state=1 where cmapversion="+version+"";
		PreparedStatement pst = openConnect().prepareStatement(sql);
		
		
		return pst.executeUpdate() > 0;
	}
	/**
	 * update tinh trang user_assi
	 */
	public boolean UpDateStateUA(String user,int ass) throws Exception {
		String sql = "update user_assi set state=1 where assi="+ass+" and username='"+user+"'";
		PreparedStatement pst = openConnect().prepareStatement(sql);
		
		
		return pst.executeUpdate() > 0;
	}
	/**
	 * cap nhat diem sau khi sinh vien submit
	 */
	public boolean UpDateScoreCmapstudent(int version,double score) throws Exception {
		String sql = "update cmapstudent set statesubmit=1,score="+score+" where cmapversion="+version+"";
		PreparedStatement pst = openConnect().prepareStatement(sql);
		
		
		return pst.executeUpdate() > 0;
	}
	/**
	 * them user share
	 */
	public boolean insertUserShare(ListShareStudent as) throws Exception {
		String sql = "insert into listsharestudent(UserShare,UserReceive,CmapVersion,DateShare) values(?,?,?,?)";
		//tao ra doi tuong chua cau lenh sql
		PreparedStatement pst = openConnect().prepareStatement(sql);
		
	
		pst.setString(1, as.getUserShare());
		pst.setString(2,as.getUserRecive());
		pst.setInt(3, as. getCmapVersion());
		pst.setString(4, as.getDateShare());
	
		
		return pst.executeUpdate() > 0;

	}
	/**
	 * them assignment
	 */
	public boolean insertAss(assignment as) throws Exception {
		String sql = "insert into assignment(assgnmentId,assignmentname,description,dateCreate,deadLine,lecture,state) values(?,?,?,?,?,?,?)";
		PreparedStatement pst = openConnect().prepareStatement(sql);
		
		pst.setInt(1, as.getAssignmentId());
		pst.setString(2, as.getAssiName());
		pst.setString(3,as.getDescript());
		pst.setString(4, as.getDateCreate());
		pst.setString(5,as.getDeadLine());
		pst.setString(6, as.getLecture());
		pst.setString(7, "0");
		return pst.executeUpdate() > 0;

	}
	/**
	 * ds position concept GV

	 */
	public ArrayList<posiConceptGV> getPosiByID(int assignmentId)
			throws Exception {
		ArrayList<posiConceptGV> lst = new ArrayList<posiConceptGV>();
		String sql = "SELECT assignmentId,concept1,concept2,relation FROM positionlecture where assignmentId=?";
		PreparedStatement pst = openConnect().prepareStatement(sql);
		pst.setInt(1, assignmentId);
		ResultSet rs = pst.executeQuery();
		// RalationConcept rc = null;/
		while (rs.next()) {
			posiConceptGV r = new posiConceptGV();

			r.setCmapid(rs.getInt("assignmentId"));
			r.setConcept1(rs.getString("concept1"));
			r.setConcept2(rs.getString("concept2"));
			r.setRelation(rs.getString("relation"));

			lst.add(r);
		}
		return lst;
	}
	/**
	 * chi tiet assignment theo ma assignment

	 */
	public assignment getDetailAssByID(int ass) throws Exception {
		String sql = "select * from assignment where assgnmentId=?";
		PreparedStatement pst = openConnect().prepareStatement(sql);
		pst.setInt(1, ass);
		ResultSet rs = pst.executeQuery();
		assignment sp = null;
		if (rs.next()) {
			int id=Integer.parseInt(rs.getString("assgnmentId"));
			String name = rs.getString("assignmentname");
			String decript = rs.getString("description");
			String datecreat = rs.getString("dateCreate");
			String dateLine = rs.getString("deadLine");
			String lecture = rs.getString("lecture");
			
			sp = new assignment(id, name, decript, datecreat, dateLine, lecture
				);
		}
		return sp;
	}
	public ArrayList<String> listerror  = new ArrayList<String>();
	/**
	 * cham diem
	 */
	public double cham(ArrayList<RalationConcept> RlSV, ArrayList<posiConceptGV> RlGV)
	{
		double d=0.0;
		double tb=10/RlGV.size();
		
		for (RalationConcept sv : RlSV) {		
			
			for (posiConceptGV gv : RlGV) {
				boolean concept1=sv.getConcept1().trim().equals(gv.getConcept1().trim());
				boolean concept2=sv.getConcept2().trim().equals(gv.getConcept2().trim());
				boolean relation=sv.getRelation().trim().equals(gv.getRelation().trim());
				if(concept1&&concept2&&relation){
					d=d+tb;
					
					break;
				}
				else if(concept1&&concept2&&!relation||concept1&&!concept2&&relation||!concept1&&concept2&&relation)
				{
					listerror.add("Location Error: "+sv.getConcept1().trim()+"-"+sv.getRelation().trim()+"-"+sv.getConcept2().trim());//Relation sai
					d=d+(tb/3)*2;
					
					break;
				}
				
			}
			
		}

        DecimalFormat df = new DecimalFormat("0.00"); 
		return (Double.parseDouble(df.format(d)));
      
	}
	/**
	 * giao bai tap insert user_assi
	 */
	public boolean insertUserAssi(User_Assi ua) throws Exception {
		String sql = "insert into user_assi(classid,assi,date,username) values(?,?,?,?)";
		PreparedStatement pst = openConnect().prepareStatement(sql);
		pst.setString(1,ua.getClassID());
		pst.setInt(2, ua.getAss());
		pst.setString(3, ua.getDate());
		pst.setString(4, ua.getUser());
	
		return pst.executeUpdate() > 0;

	}

	public User getUser(String User) throws Exception{
		String sql = "select UserName,Password,RoleID from user where UserName='"+User+"'";
		PreparedStatement pst = openConnect().prepareStatement(sql);
		ResultSet rs = pst.executeQuery();
		User sp = null;
		if (rs.next()) {
				String user = rs.getString("UserName");
				String pass = rs.getString("PassWord");
				int role =Integer.parseInt(rs.getString("RoleID"));

				 sp = new User(user, pass,role);
				
		}
		return sp;

	}
	public int  checkRole(String User)
	{
		 int t=-1;
		 try
		 {
		User listAcc = getUser(User);
		
			if(listAcc.getRole()==1)
			t=1;
			else
				t=0;
		 }
		 catch(Exception e)
		 {}
				
		
		return t;
	}

	public boolean checkAccount(String userName, String passWord) {
		ArrayList<User> listAcc = getListUser();
		if (userName == null || passWord == null) {
			return false;
		} else {
			for (int i = 0; i < listAcc.size(); i++) {
				if (listAcc.get(i).getUserName().equals(userName)
						&& listAcc.get(i).getPass().equals(passWord)) {
					return true;
				}
			}
			return false;
		}

	}

	/**
	 * ds acount
	 */
	public ArrayList<RalationConcept> getListAcount() {
		String sql = "select * from propositionstudent";
		ArrayList<RalationConcept> lst = new ArrayList<RalationConcept>();
		try {
			rs = getStatement().executeQuery(sql);
			while (rs.next()) {
				int id = rs.getInt("id");
				String concept1 = rs.getString("concept1");
				String concept2 = rs.getString("concept2");
				String relation = rs.getString("relation");
				RalationConcept rc = new RalationConcept(concept1, concept2,
						relation);
				lst.add(rc);
			}
		} catch (Exception e) {
		}
		return lst;

	}
	/**
	 * lay ten lop theo username
	 */
	public User getClassID(String user) throws Exception {
		String sql = "select * from user where UserName='"+user+"' ";
		PreparedStatement pst = openConnect().prepareStatement(sql);
		// pst.setInt(1, cmapv);
		ResultSet rs = pst.executeQuery();
		User sp = null;
		if (rs.next()) {
			
			String username = rs.getString("UserName");
			String classId = rs.getString("classID");
		
			sp = new User(username,classId);
		}
		return sp;
	}
	/**
	 * lay diem version
	 */
	public cmapstudent getScore(int  versionid) throws Exception {
		String sql = "select * from cmapstudent where cmapversion='"+versionid+"' ";
		PreparedStatement pst = openConnect().prepareStatement(sql);
		// pst.setInt(1, cmapv);
		ResultSet rs = pst.executeQuery();
		cmapstudent sp = null;
		if (rs.next()) {
					int cmapversion = Integer.parseInt(rs.getString("cmapversion"));
			String submitdate = rs.getString("submitday");
			double score = Double.parseDouble(rs.getString("score"));
			String user = rs.getString("usernamestudent");
			int assi = Integer.parseInt(rs.getString("idAssi"));
			sp = new cmapstudent(cmapversion,submitdate,score,user,assi);
		}
		return sp;
	}
	/**
	 * lay danh sach assignment trong user_assi theo classID
	 */
	public ArrayList<User_Assi> getListAssbyClassID(String classID) {
		String sql = "select * from user_assi where classid='"+classID+"'";
		ArrayList<User_Assi> lst = new ArrayList<User_Assi>();
		try {
			rs = getStatement().executeQuery(sql);
			while (rs.next()) {
				
				String classid = rs.getString("classid");
				int ass = Integer.parseInt(rs.getString("assi"));
				String date= rs.getString("date");
				User_Assi au = new User_Assi(classid, ass, date);
				lst.add(au);
			}
		} catch (Exception e) {
		}
		return lst;

	}
	/**
	 * lay danh sach version chua submit trong cmapstudent theo user
	 */
	public ArrayList<cmapstudent> getListCmapStudent(String user,int ass) {
		String sql = "select * from cmapstudent where usernamestudent='"+user+"' and statesubmit='0' and state='1'and idAssi="+ass+"";
		ArrayList<cmapstudent> lst = new ArrayList<cmapstudent>();
		try {
			rs = getStatement().executeQuery(sql);
			while (rs.next()) {
				int id = rs.getInt("cmapversion");
				String date = rs.getString("submitday");
				Double score = Double.parseDouble(rs.getString("score"));
				String userstudent = rs.getString("usernamestudent");
				int idAss = rs.getInt("idAssi");
				cmapstudent rc = new cmapstudent(id, date, score, userstudent,idAss);
				lst.add(rc);
			}
		} catch (Exception e) {
		}
		return lst;

	}
	/**
	 * lay danh sach version da submit trong cmapstudent theo user
	 */
	public ArrayList<cmapstudent> getListCmapStudentSM(String user) {
		String sql = "select * from cmapstudent where usernamestudent='"+user+"' and statesubmit='1' and state='1'";
		ArrayList<cmapstudent> lst = new ArrayList<cmapstudent>();
		try {
			rs = getStatement().executeQuery(sql);
			while (rs.next()) {
				int id = rs.getInt("cmapversion");
				String date = rs.getString("submitday");
				Double score = Double.parseDouble(rs.getString("score"));
				String userstudent = rs.getString("usernamestudent");
				int idAss = rs.getInt("idAssi");
				cmapstudent rc = new cmapstudent(id, date, score, userstudent,idAss);
				lst.add(rc);
			}
		} catch (Exception e) {
		}
		return lst;

	}
	/**
	 * lay danh sach version chưa submit trong cmapstudent theo user
	 */
	public ArrayList<cmapstudent> getListCmapStudentCL(String user,int ass) {
		String sql = "select * from cmapstudent where usernamestudent='"+user+"' and state='0' and idAssi="+ass+"";
		ArrayList<cmapstudent> lst = new ArrayList<cmapstudent>();
		try {
			rs = getStatement().executeQuery(sql);
			while (rs.next()) {
				int id = rs.getInt("cmapversion");
				String date = rs.getString("submitday");
				Double score = Double.parseDouble(rs.getString("score"));
				String userstudent = rs.getString("usernamestudent");
				int idAss = rs.getInt("idAssi");
				cmapstudent rc = new cmapstudent(id, date, score, userstudent,idAss);
				lst.add(rc);
			}
		} catch (Exception e) {
		}
		return lst;

	}
	/**
	 * them moi version
	 */
	public boolean insertCmapStu(cmapstudent cm) throws  Exception
	{
		String sql = "insert into cmapstudent(submitday,score,usernamestudent,idAssi,state,statesubmit) values(?,?,?,?,?,?)";
		PreparedStatement pst = openConnect().prepareStatement(sql);
		pst.setString(1, cm.getDatesubmit());
		pst.setDouble(2, 0);
		pst.setString(3, cm.getUsernamestudent());
		pst.setInt(4,cm.getIdAss());
		pst.setString(5,"0");
		pst.setString(6,"0");


		return pst.executeUpdate() > 0;

	}
	public ArrayList<RalationConcept> getConceptByID(int cmapv)
			throws Exception {
		ArrayList<RalationConcept> lst = new ArrayList<RalationConcept>();
		String sql = "SELECT cmapversion,concept1,concept2,relation FROM propositionstudent where cmapversion=?";
		PreparedStatement pst = openConnect().prepareStatement(sql);
		pst.setInt(1, cmapv);
		ResultSet rs = pst.executeQuery();
		// RalationConcept rc = null;
		while (rs.next()) {
			RalationConcept r = new RalationConcept();

			r.setCmapversion(rs.getInt("cmapversion"));
			r.setConcept1(rs.getString("concept1"));
			r.setConcept2(rs.getString("concept2"));
			r.setRelation(rs.getString("relation"));

			lst.add(r);
		}
		return lst;
	}

	public RalationConcept getCMByID() throws Exception {
		String sql = "select * from propositionstudent ";
		PreparedStatement pst = openConnect().prepareStatement(sql);
		// pst.setInt(1, cmapv);
		ResultSet rs = pst.executeQuery();
		RalationConcept sp = null;
		if (rs.next()) {
			int conceptversion = Integer.parseInt(rs.getString("cmapversion"));
			String concept1 = rs.getString("concept1");
			String concept2 = rs.getString("concept2");
			String relation = rs.getString("relation");

			sp = new RalationConcept(conceptversion, concept1, concept2,
					relation);
		}
		return sp;
	}
/**insert position giang vien
 * 
 
 */
	public boolean insertPosGV(posiConceptGV pc) throws  Exception
	{
		String sql = "insert into positionlecture(assignmentId,concept1,concept2,relation) values(?,?,?,?)";
		PreparedStatement pst = openConnect().prepareStatement(sql);
		
		pst.setInt(1, pc.getCmapid());
		pst.setString(2, pc.getConcept1());
		pst.setString(3, pc.getConcept2());
		pst.setString(4,pc.getRelation());


		return pst.executeUpdate() > 0;

	}
	public boolean insertNew(RalationConcept sp) throws Exception {
		String sql = "insert into propositionstudent(cmapversion,concept1,concept2,relation) values(?,?,?,?)";
		PreparedStatement pst = openConnect().prepareStatement(sql);
		pst.setInt(1,sp.getCmapversion());
		pst.setString(2, sp.getConcept1());
		pst.setString(3, sp.getConcept2());
		pst.setString(4, sp.getRelation());

		return pst.executeUpdate() > 0;

	}

	
	public int executeUpdate(String strSQL) throws Exception {
		int result = 0;
		try {
			result = getStatement().executeUpdate(strSQL);
		} catch (Exception ex) {
			throw new Exception(ex.getMessage() + " Error at: " + strSQL);
		} finally {
			this.closeConnet();
		}
		return result;
	}

	/**
	 * A method to close the connection.
	 * 
	 * @throws SQLException
	 */
	public void closeConnet() throws SQLException {
		if (rs != null && !rs.isClosed())
			rs.close();
		if (stmt != null)
			stmt.close();
		if (connect != null)
			connect.close();
	}
	//insert concept relation giang vien
	public void insertPossiGV(int assignmentId)
	{
		RalationConcept rc = new RalationConcept();
		String concept1;
		String concept2;
		String relation;
		try {

			String duongdan = "C:/Users/LungNgan/workspace/Concept/TestFile.txt";
			FileInputStream file = new FileInputStream(duongdan);
			DataInputStream dataFile = new DataInputStream(file);
			String t = dataFile.readLine();
			Scanner input = new Scanner(dataFile);

			while (t != null&&input.hasNextLine()!=false) {

				
				while (input.hasNextLine()) {
					String line = input.nextLine();

					if (line.trim() != "") {
						String items[] = line.split("\"");
						concept1 = items[0].toString();
						concept2 = items[2].toString();
						relation = items[1].toString();
						posiConceptGV k = new posiConceptGV(assignmentId,concept1,
								concept2, relation);
						insertPosGV(k);
						// System.out.print(t);
					}

					// input.close();
				}

			}
		} catch (Exception e) {
			System.out.println("Lỗi" + e.getMessage());
		}

	}
//insert concept relation sinh vien
	public void LoadDatabase(int idCmap) {
		RalationConcept rc = new RalationConcept();
		String concept1;
		String concept2;
		String relation;
		try {

			String duongdan = "C:/Users/LungNgan/workspace/Concept/TestFile.txt";
			FileInputStream file = new FileInputStream(duongdan);
			DataInputStream dataFile = new DataInputStream(file);
			String t = dataFile.readLine();
			Scanner input = new Scanner(dataFile);

		do {

				
				 do{
					String line = input.nextLine();

					if (line.trim() != "") {
						String items[] = line.split("\"");
						concept1 = items[0].toString();
						concept2 = items[2].toString();
						relation = items[1].toString();
						RalationConcept k = new RalationConcept(idCmap,concept1,concept2, relation);
						insertNew(k);
						// System.out.print(t);
					}

					// input.close();
				}while (input.hasNextLine());

			}while(t != null&&input.hasNextLine()!=false);
		
		} catch (Exception e) {
			System.out.println("Lỗi" + e.getMessage());
		}

	}

	public void GhiFile(String data) {
		String str;
		FileWriter fw;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			fw = new FileWriter(
					"C:/Users/LungNgan/workspace/Concept/TestFile.txt");

			// data = br.readLine();

			fw.write(data);

			fw.close();

		} catch (IOException exc) {
			System.out.println("Có lỗi xảy ra");

		}

	}

	public static void main(String[] args) throws Exception {
		// RalationConcept sp=new RalationConcept("abc","Ä‘f","sdf");
		ConnectDB db = new ConnectDB();
//db.LoadDatabase();
//assignment as=new assignment( "1","1","2","2","2","3");
//ListShareStudent us=new ListShareStudent("1","2",1,"df");
//ArrayList<User_Assi > dx=new ConnectDB().getAssStudentCL("lungngan");

	}
}
